function member_business()
{
	//#################################################################
	//
	// 조회부
	//
	//#################################################################
	// 목록 조회
	var _listPage 	= new PageInfo( document.getElementById( 'selectBusinesses' ) );
	$( "#businessRefresh" ).click(function(e) {
		selectAllBusinesses( _listPage.current, _listPage.numPerPage, businessRefreshSuccess, businessRefreshFail );
	});
	
	// 조회 성공
	function businessRefreshSuccess( data )
	{
		// 성공 핸들러
		setResult( '[사업 조회] 성공' );
		
		setBusinessListTable( data, $( "#selectBusinesses>.list" ), _listPage );
	}
	
	// 조회 실패
	function businessRefreshFail( data )
	{
		setResultFail( '[사업 조회] 실패', data );
	};
	
	// 상세 팝업 활성
	function showUpdateBusinessPopup( $business_code )
	{
		$.post( getGatePath(),
			{
				__key__: 'selectBusiness',
				__returnType__: 'json',
				login_member_id: login_member_id(),
				login_member_session: login_member_session(),
				businessCode: $business_code
			}, 
			function( data )
			{
				if( data.result == "SUCCESS" )
				{
					setResult( '[사업 상세 정보 조회] 성공' );
					
					// [[ 팝업 셋팅 ]]
					$popup = $( "#updateBusiness" );
					$popup.show();
					
					// 팝업이 설정과 동시에 공통변수 설정
					$popup.find( '.businessCode' ).val( data[ 'code' ] );
					
					$popup.find( '[name="code"]' ).val(		data[ 'code' ] );
					$popup.find( '[name="name"]' ).val( 	data[ 'name' ] );
								
					// 썸네일 정보
					var _thumbnails = [];
					if( data[ 'thumbnails' ] && data[ 'thumbnails' ][ 'thumb' ] )
					{
						for( var idx in data[ 'thumbnails' ][ 'thumb' ] )
						{
							var _link = data[ 'thumbnails' ][ 'thumb' ][ idx ].link;
							_thumbnails.push( 'no.'+(idx+1)+' '+_link+'('+createViewImageLink(_link)+')' );
						}
					}
					$popup.find( '.thumbs' ).empty().append( _thumbnails.join( '<br/>' ) );	
					
					
					// 기타 설정
					$popup.find( '[name="bCode"]' ).val( 		data[ 'b_code' ] );
					$popup.find( '[name="name"]' ).val( 		data[ 'name' ] );
					$popup.find( '[name="pDate"]' ).val( 		data[ 'propose_date' ] );
					$popup.find( '[name="dDate"]' ).val( 		data[ 'decision_date' ] );
					$popup.find( '[name="ref"]' ).val( 			data[ 'ref' ] );
					$popup.find( '[name="ref_license"]' ).val( 	data[ 'ref_license' ] );
					
					// 링크 정보
					selectBusinessLinks( data[ 'code' ] );
					// 태그 정보
					selectBusinessTags( data[ 'code' ] );
					
					
					// [준비중]관련 정치인 조회
					
					// 즐겨찾기
					selectMemberBusinessFavorite( $business_code );
					// 댓글 가져오기
					$( '#btn_businessCommentRefresh' ).click();
					// 투표 정보
					selectBusinessVote( data[ 'code' ] );
				}else{
					setResultFailForJSON( '[사업 상세 정보 조회] 실패', data );
				}
			},
			'json' );
	}
	
	// 2. 조회
	function selectBusinessLinks( $businessCode )
	{
		$.post(
			getGatePath()
			,
			{
				__key__: 'selectBusinessLinks',
				__returnType__: 'json',
				login_member_id: login_member_id(),
				login_member_session: login_member_session(),
				businessCode: $businessCode
			}
			,
			function( data )
			{
				if( data.result == 'SUCCESS' )
				{
					setResult( '[사업 링크 조회] 성공' );
					
					var $listContainer = $( '#businessLinks>.list' );
					// 비우기
					$listContainer.empty();
					
					// 타이틀 추가
					var _tr;
					_tr = "<thead>";
					_tr += "<tr>";
					_tr += 		"<td>NO</td>";
					_tr +=  	"<td>LINK</td>";
					_tr +=  	"<td>VIEW</td>";
					_tr += "</tr>";
					_tr += "</thead>";
					_tr += "<tbody>";
					// 리스트 추가
					var _no = 1;
					for( var index in data.link )
					{
						var _item = data.link[ index ];
						_tr += "<tr>";
						_tr += 		"<td>"+(_no++)+"</td>";
						_tr += 		"<td>"+_item[ 'link' ]+"</td>";
						_tr += 		"<td>"+"<a href='"+_item[ 'link' ]+"' target='_blank'>VIEW</a>"+"</td>";
						_tr += "</tr>";
					}
					_tr += "</tbody>";
					$listContainer.append( _tr );
				}else{
					setResultFailForJSON( '[사업 링크 조회] 실패', data );
				}
			}
			,
			'json' 
		);
	}
	function selectBusinessTags( $businessCode )
	{
		$.post(
			getGatePath()
			,
			{
				__key__: 'selectBusinessTags',
				__returnType__: 'json',
				login_member_id: login_member_id(),
				login_member_session: login_member_session(),
				businessCode: $businessCode
			}
			,
			function( data )
			{
				if( data.result == 'SUCCESS' )
				{
					setResult( '[사업 태그 조회] 성공' );
					
					var $listContainer = $( '#businessTags>.list' );
					// 비우기
					$listContainer.empty();
					
					// 타이틀 추가
					var _tr;
					_tr = "<thead>";
					_tr += "<tr>";
					_tr += 		"<td>NO</td>";
					_tr +=  	"<td>TAG</td>";
					_tr += "</tr>";
					_tr += "</thead>";
					_tr += "<tbody>";
					// 리스트 추가
					var _no = 1;
					for( var index in data.tag )
					{
						var _item = data.tag[ index ];
						_tr += "<tr>";
						_tr += 		"<td>"+(_no++)+"</td>";
						_tr += 		"<td>"+_item[ 'tag' ]+"</td>";
						_tr += "</tr>";
					}
					_tr += "</tbody>";
					$listContainer.append( _tr );
					
				}else{
					setResultFailForJSON( '[사업 태그 조회] 실패', data );
				}
			}
			,
			'json' 
		);
	}
	//#################################################################
	//
	// 즐겨 찾기
	//
	//#################################################################
	// 조회
	function selectMemberBusinessFavorite( $business_code )
	{
		// 값을 담아둠
		$( '#btn_businessFavorite' ).attr( 'businessCode', $business_code );
		
		$.post(
			getGatePath()
			,
			{
				__key__: 'selectMemberBusinessFavorite',
				__returnType__: 'json',
				login_member_id: login_member_id(),
				login_member_session: login_member_session(),
				businessCode: $business_code
			}
			,
			favoriteButtonRefresh
			,
			'json' );
	}
	
	// 업데이트
	$( '#btn_businessFavorite' ).click( function(e)
	{
		if( $( this ).attr( 'businessCode' ) == undefined ) return;
		
		// 'Y', 'N'
		var $isFavorite = $( this ).attr( 'isFavorite' ) == 'Y';
		var $business_code = $( this ).attr( 'businessCode' );
		
		if( $isFavorite )
		{
			// 해제
			$.post(
				getGatePath()
				,
				{
					__key__: 'deleteMemberBusinessFavorite',
					__returnType__: 'json',
					login_member_id: login_member_id(),
					login_member_session: login_member_session(),
					businessCode: $business_code
				}
				,
				favoriteButtonRefresh
				,
				'json'
			);
		}else{
			// 등록
			$.post(
				getGatePath()
				,
				{
					__key__: 'insertMemberBusinessFavorite',
					__returnType__: 'json',
					login_member_id: login_member_id(),
					login_member_session: login_member_session(),
					businessCode: $business_code
				}
				,
				favoriteButtonRefresh
				,
				'json'
			);
		}
			
		
		
	});
	
	function favoriteButtonRefresh( data )
	{
		if( data.result == 'SUCCESS' )
		{
			setResult( '[즐겨찾기] 성공' );
			if( data[ 'isFavorite' ] == 'Y' )
			{
				// 즐겨찾기에 등록되어 있는 모델이면, 해제 버튼으로 설정한다.
				$( '#btn_businessFavorite' ).attr( 'isFavorite', 'Y' );
				$( '#btn_businessFavorite' ).val( 'Like Down' );
			}else{
				// 즐겨찾기에 등록된 모델이 아니면, 등록 버튼으로 설정한다.
				$( '#btn_businessFavorite' ).attr( 'isFavorite', 'N' );
				$( '#btn_businessFavorite' ).val( 'Like Up' );
			}
		}else{
			setResultFailForJSON( '[즐겨찾기] 실패', data );
			$( '#btn_businessFavorite' ).removeAttr( 'businessCode' );
			$( '#btn_businessFavorite' ).removeAttr( 'isFavorite' );
			$( '#btn_businessFavorite' ).val( 'Impossible' );
		}
	}
	//#################################################################
	//
	// 댓글 달기
	//
	//#################################################################
	// 목록 조회
	var _commentPage 	= new PageInfo( document.getElementById( 'businessComments' ) );
	_commentPage.numPerPage = 5;
	$( '#btn_businessCommentRefresh' ).click(function(e) {
        selectAllBusinessComments( _commentPage.current, _commentPage.numPerPage, businessCommentsRefreshSuccess, businessCommentsRefreshFail );
    });
	
	function selectAllBusinessComments( page, numPerPage, completeHandler, failHandler )
	{
		$.post( getGatePath(),
		{
			__key__: 'selectBusinessComments',
			__returnType__: 'json',			
			login_member_id: login_member_id(),
			login_member_session: login_member_session(),
			businessCode: $( '#insertBusinessCommentForm' ).find( '.businessCode' ).val(),
			page: page,
			numPerPage: numPerPage
		},
		function( data )
		{
			if( data.result == "SUCCESS" )
			{
				// 완료 콜백
				if( completeHandler )
				{
					completeHandler.call( null, data );
				}
			}else{
				// 실패 콜백
				if( failHandler )
				{
					failHandler.call( null, data );
				}
			}
		},
		'json');
	}
	// 조회 성공
	function businessCommentsRefreshSuccess( data )
	{
		// 성공 핸들러
		setResult( '[사업 댓글 조회] 성공' );
		
		var $listContainer = $( "#businessComments>.list" );
		// 비우기
		$listContainer.find( '.btnDelete' ).unbind( "click" );
		$listContainer.empty();
		
		// 타이틀 추가
		var _tr;
		_tr = "<thead>";
		_tr += "<tr>";
		_tr += 		"<td>NO</td>";
		_tr +=  	"<td>댓글</td>";
		_tr +=  	"<td>작성자</td>";
		_tr +=  	"<td>등록일</td>";
		_tr +=  	"<td>DELETE</td>";
		_tr += "</tr>";
		_tr += "</thead>";
		_tr += "<tbody>";
		// 리스트 추가
		var _no = (_commentPage.current-1)*_commentPage.numPerPage+1;
		for( var index in data.comment )
		{
			var _item = data.comment[ index ];
			_tr += "<tr>";
			_tr += 		"<td>"+(_no++)+"</td>";
			_tr += 		"<td>"+_item[ 'comment' ]+"</td>";
			_tr += 		"<td>"+_item[ 'nickname' ]+"</td>";
			_tr += 		"<td>"+_item[ 'register' ]+"</td>";
			_tr += 		"<td>"+(_item[ 'owner_id' ]==login_member_id()?"<input type='button' class='btnDelete' value='DELETE' data='"+_item[ 'seq' ]+"'/>":'')+"</td>";			
			_tr += "</tr>";
		}
		_tr += "</tbody>";
		$listContainer.append( _tr );
		
		// 수정 버튼 이벤트 등록
		$listContainer.find( '.btnDelete' ).bind( "click", null, function(e) {
			var $comment_seq = $(this).attr( 'data' );
			deleteBusinessComment( $comment_seq );
		});
		
		// 페이징
		_commentPage.setTotalCount( data.count );
		_commentPage.updateLabelField();
	}
	
	// 조회 실패
	function businessCommentsRefreshFail( data )
	{
		setResultFail( '[사업 댓글 조회] 실패', data );
	};
	
	// 입력
	$( '#insertBusinessCommentForm' ).submit(function(e) {
        e.preventDefault();
		
		
		var _formData = new FormData( document.getElementById( 'insertBusinessCommentForm' ) );
		_formData.append( '__key__', 'insertMemberBusinessComment' );
		_formData.append( '__returnType__', 'json' );
		_formData.append( 'login_member_id', login_member_id() );
		_formData.append( 'login_member_session', login_member_session() );
		
		$.ajax(
		{
			url: getGatePath(),
			data: _formData,
			dataType:'json',
			processData: false,
			contentType: false,
			type: "POST",
			success: function( data )
			{
				if( data.result == 'SUCCESS' )
				{
					setResult( '[코멘트 추가] 성공' );
					// 리스트 갱신
					selectAllBusinessComments( _commentPage.current, _commentPage.numPerPage, businessCommentsRefreshSuccess, businessCommentsRefreshFail );
				}else{
					setResultFailForJSON( '[코멘트 추가] 실패', data );
				}
			}
		});
    });
	
	// 댓글 삭제
	function deleteBusinessComment( $comment_seq )
	{
		$.post(
			getGatePath()
			,
			{
				__key__: 'deleteMemberBusinessComment',
				__returnType__: 'json',
				login_member_id: login_member_id(),
				login_member_session: login_member_session(),
				seq: $comment_seq
			}
			,
			function( data )
			{
				if( data.result == 'SUCCESS' )
				{
					setResult( '[코멘트 삭제] 성공' );
					// 리스트 갱신
					selectAllBusinessComments( _commentPage.current, _commentPage.numPerPage, businessCommentsRefreshSuccess, businessCommentsRefreshFail );
				}else{
					setResultFailForJSON( '[코멘트 삭제] 실패', data );
				}
			}
			,
			'json' );
	}
	
	//#################################################################
	//
	// 즐겨찾기 모델 조회부
	//
	//#################################################################
	// 목록 조회
	var _favoriteBusinessListPage 	= new PageInfo( document.getElementById( 'selectFavoriteBusinesses' ) );
	$( "#favoriteBusinessRefresh" ).click(function(e) {
		selectFavoriteBusiness( _favoriteBusinessListPage.current, _favoriteBusinessListPage.numPerPage, favoriteBusinessRefreshSuccess, favoriteBusinessRefreshFail );
	});
	function selectFavoriteBusiness( page, numPerPage, completeHandler, failHandler )
	{
		$.post( getGatePath(),
		{
			__key__: 'selectFavoriteBusinesses',
			__returnType__: 'json',
			login_member_id: login_member_id(),
			login_member_session: login_member_session(),
			page: page,
			numPerPage: numPerPage
		},
		function( data )
		{
			if( data.result == "SUCCESS" )
			{
				// 완료 콜백
				if( completeHandler )
				{
					completeHandler.call( null, data );
				}
			}else{
				// 실패 콜백
				if( failHandler )
				{
					failHandler.call( null, data );
				}
			}
		},
		'json' );
	}
	// 조회 성공
	function favoriteBusinessRefreshSuccess( data )
	{
		// 성공 핸들러
		setResult( '[사업 조회] 성공' );
		
		setBusinessListTable( data, $( "#selectFavoriteBusinesses>.list" ), _favoriteBusinessListPage );
	}
	
	// 조회 실패
	function favoriteBusinessRefreshFail( data )
	{
		setResultFail( '[사업 조회] 실패', data );
	};
	
	//#################################################################
	//
	// 댓글남긴 모델 조회부
	//
	//#################################################################
	// 목록 조회
	var _commentBusinessListPage 	= new PageInfo( document.getElementById( 'selectCommentBusinesses' ) );
	$( "#commentBusinessRefresh" ).click(function(e) {
		selectCommentBusinesses( _commentBusinessListPage.current, _commentBusinessListPage.numPerPage, commentBusinessRefreshSuccess, commentBusinessRefreshFail );
	});
	function selectCommentBusinesses( page, numPerPage, completeHandler, failHandler )
	{
		$.post( getGatePath(),
		{
			__key__: 'selectCommentBusinesses',
			__returnType__: 'json',
			login_member_id: login_member_id(),
			login_member_session: login_member_session(),
			page: page,
			numPerPage: numPerPage
		},
		function( data )
		{
			if( data.result == "SUCCESS" )
			{
				// 완료 콜백
				if( completeHandler )
				{
					completeHandler.call( null, data );
				}
			}else{
				// 실패 콜백
				if( failHandler )
				{
					failHandler.call( null, data );
				}
			}
		},
		'json' );
	}
	// 조회 성공
	function commentBusinessRefreshSuccess( data )
	{
		// 성공 핸들러
		setResult( '[사업 조회] 성공' );
		
		setBusinessListTable( data, $( "#selectCommentBusinesses>.list" ), _commentBusinessListPage );
	}
	
	// 조회 실패
	function commentBusinessRefreshFail( data )
	{
		setResultFail( '[사업 조회] 실패', data );
	};
	
	
	
	// 조회 성공
	function setBusinessListTable( data, $listContainer, pageInfo )
	{
		// 비우기
		$listContainer.find( '.btnDetail' ).unbind( "click" );
		$listContainer.empty();
		
		// 타이틀 추가
		var _tr;
		_tr = "<thead>";
		_tr += "<tr>";
		_tr += 		"<td>NO</td>";
		_tr +=  	"<td>CODE</td>";
		_tr +=  	"<td>사업구분</td>";
		_tr +=  	"<td>사업명</td>";
		_tr +=  	"<td>제안 날짜</td>";		
		_tr +=  	"<td>결정 날짜</td>";
		_tr +=  	"<td>자료출처</td>";
		_tr +=  	"<td>DETAIL</td>";
		_tr += "</tr>";
		_tr += "</thead>";
		_tr += "<tbody>";
		// 리스트 추가
		var _no = (pageInfo.current-1)*pageInfo.numPerPage+1;
		for( var index in data.business )
		{
			var _item = data.business[ index ];
			_tr += "<tr>";
			_tr += 		"<td>"+(_no++)+"</td>";
			_tr += 		"<td>"+_item[ 'code' ]+"</td>";
			_tr += 		"<td>"+toStringByBusiness( _item[ 'b_code' ] )+"</td>";
			_tr += 		"<td>"+_item[ 'name' ]+"</td>";
			_tr += 		"<td>"+_item[ 'propose_date' ]+"</td>";			
			_tr += 		"<td>"+_item[ 'decision_date' ]+"</td>";
			_tr += 		"<td>"+_item[ 'ref' ]+"/"+_item[ 'ref_license' ]+"</td>";
			_tr += 		"<td>"+"<input type='button' class='btnDetail' value='DETAIL' data='"+_item[ 'code' ]+"'/>"+"</td>";
			_tr += "</tr>";
		}
		_tr += "</tbody>";
		$listContainer.append( _tr );
		
		// 수정 버튼 이벤트 등록
		$listContainer.find( '.btnDetail' ).bind( "click", null, function(e) {
			// alert( 'EDIT '+$(this).attr( 'data' ) );
			var $business_code = $(this).attr( 'data' );
			showUpdateBusinessPopup( $business_code );
		});
		
		// 페이징
		pageInfo.setTotalCount( data.count );
		pageInfo.updateLabelField();
	}
	
	//#################################################################
	//
	// 찬 / 반투표
	//
	//#################################################################
	$( '#insertBusinessVoteForm' ).submit(function(e) {
        e.preventDefault();
		
		var _formData = new FormData( document.getElementById( 'insertBusinessVoteForm' ) );
		_formData.append( '__key__', 'insertMemberBusinessVote' );
		_formData.append( '__returnType__', 'json' );
		_formData.append( 'login_member_id', login_member_id() );
		_formData.append( 'login_member_session', login_member_session() );
		
		$.ajax(
		{
			url: getGatePath(),
			data: _formData,
			dataType:'json',
			processData: false,
			contentType: false,
			type: "POST",
			success: function( data )
			{
				if( data.result == 'SUCCESS' )
				{
					setResult( '[사업 투표] 성공' );
				}else{
					setResultFailForJSON( '[사업 투표] 실패', data );
				}
			}
		});
    });
	// 조회
	function selectBusinessVote( $business_code )
	{
		$.post(
			getGatePath()
			,
			{
				__key__: 'selectMemberBusinessVote',
				__returnType__: 'json',
				login_member_id: login_member_id(),
				login_member_session: login_member_session(),
				businessCode: $business_code
			}
			,
			function( data )
			{
				if( data.result == 'SUCCESS' )
				{
					setResult( '[투표 상황] 성공' );
					var _vote = $( '#insertBusinessVoteForm' ).find( '[name="vote"]');
					if( data.vote )
					{
						_vote.val( data.vote );
					}else{
						_vote.val( null );
					}
				}else{
					setResultFailForJSON( '[투표 상황] 실패', data );
				}
			}
			,
			'json'
		);
	}
}